package com.jy.wms.controller;

import com.github.pagehelper.Page;
import com.jy.wms.common.SetStatus;
import com.jy.wms.common.UUIDUtils;
import com.jy.wms.common.base.BaseController;
import com.jy.wms.common.base.JsonResult;
import com.jy.wms.pojo.WmsInventoryMerge;
import com.jy.wms.service.WmsInventoryMergeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpSession;
import java.util.List;

/**
 * @ClassName: WmsInventoryMergeController
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @Author Jane
 * @Date Mon Jan 29 15:30:53 CST 2018
 */
@Controller
@RequestMapping("/wmsinventorymerge")
@Api(value = "/wmsinventorymerge", description = "盘点任务合并")
public class  WmsInventoryMergeController extends BaseController<WmsInventoryMergeService,WmsInventoryMerge> {

    @PostMapping(value = "/list")
    @ApiOperation(value = "查询盘点任务合并信息",response = JSONObject.class, notes = "查询盘点任务合并信息")
    public @ResponseBody JSONObject getWmsInventoryMerge(@RequestBody WmsInventoryMerge entity, HttpSession session) {
        Page<WmsInventoryMerge> list = new Page<WmsInventoryMerge>();
        JSONObject json = getJSONObject();
        try {

            list= baseService.baseSelectPage(entity);
            json = SetStatus.setSearchType(JSONArray.fromObject(list).toString(),(int) list.getTotal());
        }catch (Exception e) {
            e.printStackTrace();
        }
        return json;
    }

    @PostMapping(value = "delete")
    @ApiOperation(value = "删除信息",response = JSONObject.class, notes = "删除信息")
    public @ResponseBody
    JsonResult deleteWmsInventoryMerge(@RequestBody List<String> ids) {
        Integer flag=baseService.baseDeleteBathPrimaryKeys(ids);
        return renderSuccess("删除成功");
    }

    @PostMapping(value = "add")
    @ApiOperation(value = "新增信息",response = JSONObject.class, notes = "新增信息")
    public @ResponseBody
    JsonResult addWmsInventoryMerge(@RequestBody WmsInventoryMerge entity) {
        entity.setId(UUIDUtils.uuid());
        baseService.baseInsert(entity);
        return renderSuccess("添加成功");
    }

    @GetMapping(value = "getWmsInventoryMerge/{id}")
    @ApiOperation(value = "查看单个信息",response = JSONObject.class, notes = "GET查看单个信息")
    public @ResponseBody
    WmsInventoryMerge getWmsInventoryMergeById(@PathVariable("id") String id) {
        WmsInventoryMerge entity=baseService.baseSelectByPrimaryKey(id);
        return entity;
    }
    @PostMapping(value = "edit")
    @ApiOperation(value = "编辑信息",response = JSONObject.class, notes = "编辑信息")
    public @ResponseBody
    JsonResult editWmsInventoryMerge(@RequestBody WmsInventoryMerge entity) {
        Integer flag=baseService.baseUpdateByPrimaryKeySelective(entity);
        return renderSuccess("修改成功");
    }
}
